Fix static p5 vector method#8998
Conversation
|
🎉 Thanks for opening this pull request! For guidance on contributing, check out our contributor guidelines and other resources for contributors! Thank You! |
|
@ksen0 thnks ... |
Continuous ReleaseCDN linkPublished PackagesCommit hash: e09e6f7 Previous deploymentsThis is an automated message. |
| Vector._friendlyError = p5._friendlyError; | ||
| Vector.friendlyErrorsDisabled = function() { | ||
| return p5.disableFriendlyErrors; | ||
| }; |
There was a problem hiding this comment.
Here we are defining the fes in the vector class and here p5._firendlyError is a global static.
What if we don't do this and everywhere in this file wherever this._friendlyError is called we replace it with p5._friendlyError it should work the same and could look a little cleaner?
It's similar to how setHeading() is in this file (line no. 2028)?
what you think?
There was a problem hiding this comment.
yeah, It works perfectly fine in codebase, cleaniness could be maintained and we dont have to create its duplicate method.
I could apply those changes, share ur thoughts on that
There was a problem hiding this comment.
@ksen0 @perminder-17
I was trying to implement planned changes in code, but it's throwing rerference p5 is not defined.
because
Vector methods are completely blind to the p5, p5 instance introduced at bottom when it gets wrapped in vector func. Because vector sits above that wrapper, any code inside the class methods that tries to say p5._friendlyError will crash the entire library because p5 doesn't exist in that context.
we can go with the implementation I had proposed in PR.
Resolves #8930
Changes:
In
src/math/p5.Vector.js:- Properlybound _friendlyError&friendlyErrorsDisabledto the static Vector. Added earlyfalseafter the friendly error is triggered. This prevents a secondary crash.Added a new unit test suite to ensure the static FES validation works.
Screenshots of the change:

PR Checklist
npm run lintpasses